package com.travel.bhelp.user.controller;

import com.travel.bhelp.common.model.Result;
import com.travel.bhelp.user.model.User;
import com.travel.bhelp.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Result register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    public Result login(@RequestParam String username, 
                      @RequestParam String password) {
        return userService.login(username, password);
    }

    @PostMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token) {
        return userService.logout(token);
    }

    @GetMapping("/{id}")
    public Result getUser(@PathVariable Long id) {
        return Result.success(userService.getUserById(id));
    }
}
